package com.hckjsec.website.controller;

import java.util.List;

import com.hckjsec.common.utils.DateUtils;
import com.hckjsec.common.utils.SecurityUtils;
import com.hckjsec.common.utils.StringUtils;
import com.hckjsec.common.utils.sign.Base64Converter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.website.domain.WebSiteConfig;
import com.hckjsec.website.service.IWebSiteConfigService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 网站主Controller
 * 
 * @author cyt
 * @date 2021-10-14
 */
@RestController
@RequestMapping("/system/website")
public class WebSiteConfigController extends BaseController
{
    @Autowired
    private IWebSiteConfigService webSiteConfigService;

    /**
     * 获取网站主详细信息
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo()
    {
        WebSiteConfig webSiteConfig = new WebSiteConfig();
        WebSiteConfig webSiteConfig1 = new WebSiteConfig();
        webSiteConfig1.setDeptId(SecurityUtils.getDeptId());
        List<WebSiteConfig> list = webSiteConfigService.selectWebSiteConfigList(webSiteConfig1);
        if (!StringUtils.isEmpty(list)){
            webSiteConfig = list.get(0);
        }
        return AjaxResult.success(webSiteConfig);
    }

    /**
     * 新增网站主
     */
    @Log(title = "网站主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebSiteConfig webSiteConfig)
    {
        int rows = 0;
        WebSiteConfig webSiteConfig1 = new WebSiteConfig();
        webSiteConfig1.setDeptId(SecurityUtils.getDeptId());
        List<WebSiteConfig> list = webSiteConfigService.selectWebSiteConfigList(webSiteConfig1);
        if (!StringUtils.isEmpty(list)){
            webSiteConfig.setUpdatedAt(DateUtils.getNowDate());
            rows =  webSiteConfigService.updateWebSiteConfig(webSiteConfig);
        }else{
            webSiteConfig.setCreatedAt(DateUtils.getNowDate());
            webSiteConfig.setDeptId(SecurityUtils.getDeptId());
            rows =  webSiteConfigService.insertWebSiteConfig(webSiteConfig);
        }
        return toAjax(rows);
    }
}
